package com.assetmanage.service.impl;

import com.assetmanage.dao.AssetDao;
import com.assetmanage.dao.BorrowDao;
import com.assetmanage.dao.impl.AssetDaoImpl;
import com.assetmanage.dao.impl.BorrowDaoImpl;
import com.assetmanage.model.Asset;
import com.assetmanage.service.AssetService;

import java.util.List;

public class AssetServiceImpl implements AssetService {
    private AssetDao assetDao = new AssetDaoImpl();
    private BorrowDao borrowDao = new BorrowDaoImpl();

    @Override
    public List<Asset> getAllAssets() {
        return assetDao.getAllAssets();
    }

    @Override
    public List<Asset> getAssetsByDepartment(String depId) {
        return assetDao.getAssetsByDepartment(depId);
    }

    @Override
    public Asset getAssetById(String assetId) {
        return assetDao.getAssetById(assetId);
    }

    @Override
    public boolean addAsset(Asset asset) {
        return assetDao.addAsset(asset);
    }

    @Override
    public boolean updateAsset(Asset asset) {
        return assetDao.updateAsset(asset);
    }

    @Override
    public boolean deleteAsset(String assetId) {
        // 检查是否存在未归还的借用记录
        if (!borrowDao.getBorrowsByAsset(assetId).isEmpty()) {
            return false;
        }
        return assetDao.deleteAsset(assetId);
    }

    @Override
    public boolean checkAssetAvailable(String assetId, int num) {
        Asset asset = getAssetById(assetId);
        return asset != null && asset.getAssetNum() >= num;
    }

    @Override
    public boolean updateAssetStatus(String assetId, int assetNum) {
        return assetDao.updateAssetStatus(assetId, assetNum);
    }
} 